package cn.tedu.weibo.mapper;

import cn.tedu.weibo.vo.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Insert("insert into comment values(null, #{content}, #{author}, #{created}, #{weiboId}, #{userId})")
    void insert(Comment comment);

    /*
        如果表字段和实体类中属性名不一致，查询数据时无法自动封装
        需要通过Resule注解进行指定
     */
    @Select("select id,content,author,created,user_id from comment where weibo_id = #{weiboId}")
    @Result(property = "userId", column = "user_id")
    List<Comment> selectByWeiboId(int weiboId);

    @Delete("delete from comment where id = #{id}")
    void delete(int id);
}
